package com.example.temp.mapper;

import com.example.temp.entity.ClassEntity;
import com.example.temp.entity.Teacher;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface ClassMapper {
    // 插入班级
    @Insert("INSERT INTO class(CLASSNAME, NUMBEROFSTUDENTS, TEACHERID) VALUE (#{className}, #{numberOfStudents}, #{teacherID})")
    int insert(ClassEntity class1);

    // 修改班级信息
    int update(ClassEntity class1);

    // 查询分页
    @Select("SELECT * FROM Class where class.ClassName LIKE CONCAT('%',#{params.query},'%') LIMIT #{params.pageNum}, #{params.pageSize}")
    List<ClassEntity> search(@Param("params") Map<String, Object> params);

    // 查询班级
    @Select("SELECT * from class where ClassName = #{className}")
    ClassEntity queryClass(@Param("className") String className);

    // 查询数据总数
    @Select("SELECT COUNT(*) FROM class WHERE class.ClassName LIKE CONCAT('%',#{query},'%')")
    int getTotal(@Param("query") String query);

    // 删除班级
    @Delete("DELETE FROM class WHERE ClassName = #{className}")
    Integer delete(@Param("className") String className);

    // 获取班级名称
    @Select("select ClassName from class")
    List<String> acquireName();
    
    // 获取所有班级
    @Select("SELECT * FROM class")
    List<ClassEntity> findAll();
    
    // 根据教师ID查询其负责的班级
    @Select("SELECT * FROM class WHERE TeacherID = #{teacherId}")
    List<ClassEntity> findByTeacherId(@Param("teacherId") Object teacherId);
    
    // 根据班级ID查询班级
    @Select("SELECT * FROM class WHERE ClassId = #{classId}")
    ClassEntity findById(@Param("classId") Integer classId);
    
    // 更新班级学生列表
    @Update("UPDATE class SET NumberOfStudents = #{studentList} WHERE ClassId = #{classId}")
    int updateStudentList(@Param("classId") Integer classId, @Param("studentList") String studentList);
}
